<template>
  <div class="app-system-menu-report">
    <div class="menu-report-tips">
      设置月度报表提交时间<br>
      请填写1-31作为提交报表的时间限制依据<br>
      当前设置提交时间: <span>{{ startTime }}</span> 号-
      <span>{{ endTime }}</span> 号
    </div>
    <el-form label-width="80px" :model="time" style="padding: 0 60% 0 5%">
      <el-form-item label="开始时间">
        <el-input
          v-model="time.start"
          placeholder="暂未设置开始时间"
        />
      </el-form-item>
      <el-form-item label="结束时间">
        <el-input v-model="time.end" placeholder="暂未设置结束时间" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="subTime">确认提交</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { submitTime, getTime } from '@/api/system'
import { getInfo, getRoles } from '@/api/user'
import { getToken } from '@/utils/auth'
export default {
  components: {},
  data() {
    return {
      startTime: 0,
      endTime: 0,
      time: {
        start: '',
        end: ''
      }
    }
  },
  created() {
    this.getUserInfo()
    this.getTime()
  },
  methods: {
    getTime() {
      new Promise((resolve, reject) => {
        getTime().then((res) => {
          this.startTime = res.data[0].start == null ? 0 : res.data[0].start
          this.endTime = res.data[0].end == null ? 0 : res.data[0].end

          console.log(res.data)
        })
      })
    },
    subTime() {
      new Promise((resolve, reject) => {
        submitTime({ time: this.time }).then((resolve) => {
          this.$message({
            type: 'success',
            message: '提交成功!'
          })
          this.getTime()
        })
      })
    },
    // 获取当前用户的登录信息
    getUserInfo() {
      new Promise((resolve, reject) => {
        getInfo().then((response) => {
          // this.username = response.data.name; //当前登录用户的姓名
          this.userPermissions = response.data.per // 当前登录用户权限数组
          for (let i = 0; i < this.userPermissions.length; i++) {
            if (this.userPermissions[i] == 'update power') {
              this.is_admin = true
            }
          }
        })
      })
    }
  }
}
</script>

<style>
.app-system-menu-report {
  padding: 10px;
  width: 100%;
}
.app-system-menu-report .menu-report-tips {
  color: #e55640;
  background-color: #fce9e6;
  border-color: #edd7d4;
  padding: 15px;
  margin-bottom: 20px;
  line-height: 28px;
  font-size: 15px;
  border: 1px solid transparent;
  border-radius: 2px;
  width: 100%;
  height: auto;
  margin-bottom: 20px;
}
</style>
